import { app } from 'electron';
import fs from 'node:fs';

/*清除缓存*/
export function clearCache() {
  const userDataPath = app.getPath('userData');
  deleteDirectoryRecursive(userDataPath);
}

/*删除目录递归*/
function deleteDirectoryRecursive(dirPath) {
  console.log(dirPath);
  // fs.existsSync检查文件或目录是否存在
  if (fs.existsSync(dirPath)) {
    fs.rmSync(dirPath, {
      recursive: true,
      force: true,
    });
    console.log('delete_successfully---');
    return '1';
    // 缓存目录删除成功
  }
  // 缓存目录不存在
  console.log('cache_directory_does_not_exist');
  return '0';
}
